﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
    //var rolePermission = ViewBag.RolePermission as List<BuyWithoutLoseMoney.Core.Models.RolePermission>;
    var role = ViewBag.Role as List<BuyWithoutLoseMoney.Core.Models.Role>;
}
@model List<BuyWithoutLoseMoney.Core.Models.Permission>;
<div>
    <div class="demoTable layui-form">
        用户角色：
        <div class="layui-inline">
            <select name="roleid" id="roleid" lay-verify="required">
                <option value="0">根据角色查找相关权限</option>
                @foreach (var item in role)
                {
                    <option value="@item.Id">@item.Name</option>
                }
            </select>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" data-type="reload"><a style="color:white">搜索</a></button>
        </div>
    </div>
</div>
<div>
    <table class="layui-hide" id="demo" lay-filter="test"></table>
</div>

@section Scripts{
    <script>
        layui.use('table', function() {
            var table = layui.table;
            //第一个实例
            table.render({
                elem: '#demo'
                , url: '/admin/RolePermission/index' //数据接口
                , page: true //开启分页
                , method: "post"
                , cellMinWidth: 80
                , cols: [[ //表头
                    { type: 'checkbox', fixed: 'left' }
                    //, { field: 'id', title: 'ID', sort: true }
                    , { field: 'role', title: '角色' }
                    , { field: 'permission', title: '权限' }
                    //, { title: "操作", fixed: 'right', templet: " <span><a class='layui-btn layui-btn-danger layui-btn-sm' lay-event='del'>删除</a></span>" }

                ]]
                , id: "List"
            });
            //搜索功能
            var $ = layui.$, active = {
                reload: function() {
                    var roleid = $('#roleid');
                    //执行重载
                    table.reload('List', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            roleid: roleid.val()
                        }
                    });
                }
            };
            $('.demoTable .layui-btn').on('click', function() {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

        });
    </script>
}